package com.example.pet.controller;

import com.example.pet.beans.Pet;
import com.example.pet.common.Result;
import com.example.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * @author liukai
 * @version 1.0.0
 * @ClassName PetController.java
 * @Description TODO
 * @createTime 2021年04月21日 00:46:00
 */
@RestController
@RequestMapping(value = "/pet")
public class PetController {

    @Autowired
    private IPetService iPetService;

    @GetMapping(value = "/findAllPet")
    public Result findAllPet() {
        return iPetService.findAllPet();
    }

    @GetMapping(value = "/findAllPetByPetTypeName/{petTypeName}")
    public Result findAllPetByPetTypeName(@PathVariable() String petTypeName) {
        return iPetService.findAllPetByTypeId(petTypeName);
    }

    /**
     * 根据分类编号获取pet信息
     *
     * @param categoryId
     * @return
     */
    @GetMapping(value = "/findPetByCategoryId/{categoryId}")
    public Result findPetByCategoryId(@PathVariable Integer categoryId) {
        System.out.println(categoryId);
        return iPetService.findPetByCategoryId(categoryId);
    }

//    //    上传图片
//    @PostMapping(value = "/uploadImg/{petId}")
//    public Result uploadImg(@RequestParam(value = "file") MultipartFile file, @PathVariable("petId") String petId) {
//        System.out.println("fileName : " + file.getOriginalFilename());
//        System.out.println("petId : " + petId);
//        return iPetService.updatePetImgById(file, petId);
//    }

    /**
     * 上传图片
     *
     * @param file
     * @param petId
     * @return
     */
    @PostMapping(value = "/uploadImg")
    public Result uploadImg(@RequestParam(value = "file") MultipartFile file, String petId) {
        System.out.println("fileName : " + file.getOriginalFilename());
        System.out.println("petId : " + petId);
        return iPetService.uploadImg(file);
    }

    //    添加发布信息
    @PostMapping(value = "/addPetInfo")
    public Result addPetInfo(@RequestBody Pet pet) {
        System.out.println(pet.toString());
        return iPetService.addPet(pet);
    }

    /**
     * 根据oetId获取Pet信息
     *
     * @param petId
     * @return
     */
    @GetMapping(value = "/getPetByPetId/{petId}")
    public Result getPetByPetId(@PathVariable("petId") String petId) {
        return iPetService.findPetByPetId(petId);
    }

    /**
     * 根据petId修改pet
     * @param pet
     * @return
     */
    @PutMapping(value = "/updateImgByPetId")
    public Result updateImgByPetId(@RequestBody Pet pet) {
        System.out.println(pet.toString());
        return iPetService.updatePetImgById(pet.getPetImg(), pet.getPetId());
    }
}
